#include "mempool.h"
#include <stdio.h>
#include <assert.h>
#include <string.h>


struct student
{
	char name[16];
	int score;
	struct student *next;
};


int main(void)
{
	mempool stu_pool;
	struct student *p,*t,*test;
	
	//初始化内存池
	mempool_init(&stu_pool,sizeof(struct student),3);

	//测试申请一块内存
	test = mempool_alloc(&stu_pool);
	
	//链表第一个节点
	p = mempool_alloc(&stu_pool);
	strcpy(p->name,"jack");
	p->score = 99;

	//链表第二个节点
	p->next = mempool_alloc(&stu_pool);
	strcpy(p->next->name,"rose");
	p->next->score = 100;

	//释放内存(尝试把此语句注释看看)
	mempool_free(&stu_pool,test);

	//链表第三个节点
	p->next->next = mempool_alloc(&stu_pool);
	strcpy(p->next->next->name,"Lee");
	p->next->next->score = 98;
	p->next->next->next = NULL;

	//遍历链表
	for(t = p;t != NULL;t = t->next)
	{
		printf("name:%s\n",t->name);
		printf("score:%d\n\n",t->score);
	}

	//释放内存
	mempool_detach(&stu_pool);

	//检查程序是否跑完(没跑完说明出错)
	puts("OK");

	return 0;
}




